$(document).ready(function(){
	$("#radio").buttonset();
	
	$( "#birthday" ).datepicker({
		showOn: "button",
		buttonImage: "images/layout/calendar.png",
		buttonImageOnly: true,
		changeMonth: true,
		changeYear: true
	});
	
	$("#upload-picture").fileupload({
		dataType: 'json',
        done: function (e, data) {
            $.each(data.result, function (index, file) {
                $('<p/>').text(file.name).appendTo(".personal");
            });
        }
	});
	
	$("#save").button();
	$("#save").bind("click", function(){
		var user = {
			username: $("#username").val(),
			password: $("#password").val(),
			firstname: $("#firstname").val(),
			lastname: $("#lastname").val(),
			birthday: $("#birthday").val()
		};
		
		$.ajax({
             type: 'POST',
             url: "/dotcao/ws/users/register/save",
             data: $.toJSON(user),
             contentType: 'application/json',
             dataType: 'json',
             async: true,
             success: function (data) {
 				$("<div />").html(data.content).appendTo("#content").dialog({
					title: "Cadastro",
					show: "fade",
					hide: "fade",
					width: 300,
					height: 150,
					modal: true,
					buttons: {
						OK: function(){
							if(data.type == "SUCESSO"){
								window.location = "wall.html";
							}
							
							$(this).dialog("close");
						}
					}
				});

             }
         });
	});
	
	$("#cancel").button();
	$("#reset").button();
});